package vip.xiaonuo.megvii.faces;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import reactor.core.Reactor;
import reactor.event.Event;
import vip.xiaonuo.core.timer.TimerTaskRunner;
import vip.xiaonuo.facedoor.modular.device.entity.DeviceCategory;
import vip.xiaonuo.facedoor.modular.memberuser.entity.MemberUser;
import vip.xiaonuo.facedoor.modular.memberuser.service.FacedoorMemberUserService;
import vip.xiaonuo.facedoor.modular.topic.AiBoxEventTopic;

import javax.annotation.Resource;
import java.util.List;

/**
 * 查询有头像，但是没有旷视入库信息的人员
 */
@Component
@Slf4j
public class MemberUserInStoreTask implements TimerTaskRunner {

    @Autowired
    private Reactor reactor;

    @Resource
    private FacedoorMemberUserService userService;

    @Override
    public void action(String jobParams,String taskId) {
        query();
    }

    @Override
    public void executeXxlJob() throws InterruptedException {
        query();
    }

    private void query(){
        List<MemberUser> users = userService.findUserNotInStore(DeviceCategory.SUB_TYPE_BOX);
        for(MemberUser user : users){
            reactor.notify(AiBoxEventTopic.AVATAR_CHANGE, Event.wrap(user));
        }
    }
}
